package com.ssq.mobilehelper.global;


import com.goka.blurredgridmenu.GridMenu;
import com.goka.blurredgridmenu.GridMenuFragment;
import com.ssq.mobilehelper.R;
import com.ssq.mobilehelper.account.FrmAddbillsActivity;
import com.ssq.mobilehelper.aes.EncryptActivity;
import com.ssq.mobilehelper.compass.CompassActivity;
import com.ssq.mobilehelper.note.NoteActivity;
import com.ssq.mobilehelper.weather.activity.WeatherActivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;

import java.util.ArrayList;
import java.util.List;

/***
 *
 * TODO 主界面，可以进入其他界面
 */

public class MainActivity extends AppCompatActivity {

    private GridMenuFragment mGridMenuFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mGridMenuFragment = GridMenuFragment.newInstance(R.drawable.back);

        FragmentTransaction tx = getSupportFragmentManager().beginTransaction();
        tx.add(R.id.main_frame, mGridMenuFragment);
        //tx.addToBackStack(null);
        tx.commit();

        setupGridMenu();
/**
 *
 *  分别 进入不同的界面
 */
        mGridMenuFragment.setOnClickMenuListener(new GridMenuFragment.OnClickMenuListener() {
            @Override
            public void onClickMenu(GridMenu gridMenu, int position) {
              switch (position)
              {
                  case 0:
                      startActivity(new Intent(MainActivity.this,NoteActivity.class));
                      break;
                  case 1:
                      startActivity(new Intent(MainActivity.this,EncryptActivity.class));
                      break;
                  case 2:
                      startActivity(new Intent(MainActivity.this,FrmAddbillsActivity.class));
                      break;

                  case 3:
                      startActivity(new Intent(MainActivity.this,CompassActivity.class));
                      break;
                  case 4:
                      startActivity(new Intent(MainActivity.this, WeatherActivity.class));
                      break;
              }
            }
        });
    }

    /**
     * 设置图标
     */
    private void setupGridMenu() {
        List<GridMenu> menus = new ArrayList<>();
        menus.add(new GridMenu("记事本", R.drawable.write));
        menus.add(new GridMenu("密码管理", R.drawable.calendar));
        menus.add(new GridMenu("账单记录", R.drawable.overview));
        menus.add(new GridMenu("方位指南", R.drawable.groups));
        menus.add(new GridMenu("天气查询", R.drawable.ww2));
       // menus.add(new GridMenu("设置", R.drawable.settings));

        mGridMenuFragment.setupMenu(menus);
    }

    @Override
    public void onBackPressed() {
        if (0 == getSupportFragmentManager().getBackStackEntryCount()) {
            super.onBackPressed();
        } else {
            getSupportFragmentManager().popBackStack();
        }
    }

}
